#ifndef JBK_BASE_H
#define JBK_BASE_H

#include <vector>
#include <deque>
//#include <ext/hash_map>
#include <assert.h>


/* for unused parameters */
#ifdef UNUSED
#elif defined(__GNUC__)
#	define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#else
#	define UNUSED(x) x
#endif

/* assert, compile-time */
#define ASSERT(x) typedef int __dummy_assert_array ## __LINE__[(x) ? 1 : -1]

#include "types.h"

/* delete all the pointers to T objects in an array */
template<typename T>
void deleteall(T** a, int length) {
	T** end = a + length;
	for(T** p = a; p != end; ++p) {
		delete *p;
	}
}

/* delete all the pointers to T objects in a vector */
template<typename T>
void deleteall(std::vector<T*>& v) {
	typename std::vector<T*>::iterator it;
	for(it = v.begin(); it != v.end(); ++it) {
		delete *it;
	}
}

/* delete all the pointers to T objects in a deque */
template<typename T>
void deleteall(std::deque<T*>& v) {
	typename std::deque<T*>::iterator it;
	for(it = v.begin(); it != v.end(); ++it) {
		delete *it;
	}
}

///* delete all the pointers to V objects in a hash_map */
//template<typename K, typename V>
//void deleteallvalue(__gnu_cxx::hash_map<K, V*>& h) {
//	typename __gnu_cxx::hash_map<K, V*>::iterator it;
//	for(it = h.begin(); it != h.end(); ++it) {
//		delete it->second;
//	}
//}

#define vectorfor(type, variable, itr)   \
std::vector<type>::iterator itr; \
for(itr = variable.begin(); itr != variable.end(); ++itr)
	
template<typename T>
class pointerLessThan {
public:
	bool operator()(const T* t1, const T* t2) {
		if (t1 == 0 || t2 == 0) {
			return false;
		} else {
			return (*t1) < (*t2);
		}
	}
};

#endif	// JBK_BASE_H

